import java.time.format.TextStyle;
import java.util.HashMap;
import java.util.Map;

public class Test {
    public int findMaxLength(int[] nums) {
        Map<Integer,Integer> hash=new HashMap<>();
        hash.put(0,-1);
        int sum=0,ret=0;
        for (int i = 0; i < nums.length; i++) {
            sum+=(nums[i]==0?-1:1);
            if(hash.containsKey(sum)){
                ret=Math.max(ret,i-hash.get(sum));
            }else{
                hash.put(sum,i);
            }
        }
        return  ret;
    }

    public static void main(String[] args) {
        int[] nums={0,1};
        Test test=new Test();
        System.out.println(test.findMaxLength(nums));
    }
}
